// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: linchuan

#pragma once

#include <cstdio>
#include <string>
#include <memory>
#include <map>

#include <rapidjson/document.h>

#include "coin2/exchange/base/order/order.h"
#include "coin2/exchange/okex/symbology/currency.h"
#include "coin2/exchange/okex/symbology/product.h"

namespace coin2::exchange::okex::order_v3 {

class OkexParser : public base::order::BaseParser {
 public:
  using TransferType = coin::proto::TransferRequestProto::TransferType;

 public:
  const ParseResult& ParseRawMessage(const RawMessage& msg) override;
  // keep this api for accounting system
  AccountBalance ParseBalance(const JsonValue& document) override;

 private:
  void ParseSubmitResponse();
  void ParseAmendResponse();
  void ParseCancelResponse();
  void ParseMultiCancelResponse();
  void ParseRestOpenOrders();
  void ParseRestFillOrders();
  void ParseRestAccountBalance();
  void ParseRestTransfer();
  void ParseWsMessage();

  void ParseWsOrderInfoList(const JsonDocument& document);
  void ParseWsFillInfoList(const JsonDocument& document);
  void ParseOrderInfo(const JsonValue& data, coin::proto::ProductOrderElement* order);

 private:
  static std::map<std::string, TransferType> transfer_type_map_;
};

}  // namespace coin2::exchange::okex::order_v3
